<?php
/**
 * Created by PhpStorm.
 * User: alei
 * Date: 11/5/2017 AD
 * Time: 17:09
 */
namespace App\Models\Mysql;

//use Illuminate\Database\Eloquent\Model;
use App\Models\Traits\BaseDBMethod;

class pre_ct_translatedtext
{
	use BaseDBMethod;
	//数据库连接配置项，见config/database.php
	const DATABASE_CONF = 'lqyw_mysql';
	//pre_ct_ui 首页轮播图所在表
	const TABLE_NAME = 'pre_ct_translatedtext';

	//数据库连接配置项，见config/database.php
	//如果需要用ORM，需要设置此项
//	protected $connection = self::DATABASE_CONF;
	//表名，如果需要用ORM，需要设置此项
//	protected $table = self::TABLE_NAME;

	public static function get_tid_translatedtext(&$param)
	{
		//tid: 译文对应论坛主题帖的tid
		return self::getConnObj()->select(
			"SELECT ft.tid from pre_ct_translatedtext ct_tran, pre_forum_thread ft".
			" WHERE taskid=:taskid".
			" AND ft.authorid=:uid".
			" AND ft.tid=ct_tran.tid",
			[
				'taskid' => $param['taskid'],
				'uid' => $param['uid']
			]
		);
	}

	public static function first_tid_translatedtext($param)
	{
		$all_tid = self::get_tid_translatedtext($param);
		if($all_tid && isset($all_tid[0])) {
			return $all_tid[0]->tid;
		}
		return '';
	}

	public static function count_tid($param)
	{
		return self::getDBobj()
			->select('tid')
			->where('taskid','=',$param['taskid'])
			->count();
	}

	public static function get_weightedvotes(&$param)
	{
		return self::getConnObj()->select(
			"SELECT weightedvotes FROM pre_ct_translatedtext ct_tran, pre_forum_polloption fpo".
			" WHERE ct_tran.tid=:tid AND ct_tran.polloptionid=fpo.polloptionid",
			[
				'tid' => $param['tid']
			]
		);
	}

	public static function first_weightedvotes($param)
	{
		$all_weightedvotes = self::get_weightedvotes($param);
		if($all_weightedvotes && isset($all_weightedvotes[0])) {
			return $all_weightedvotes[0]->weightedvotes;
		}
		return '';
	}

    #获取某个任务的翻译列表
    public static function get_tid($param)
    {
        return self::getConnObj()->select(
            "SELECT tid  FROM  pre_ct_translatedtext   WHERE taskid=:taskid ",
            [
                'taskid' => $param,
            ]
        );

    }

    #获取某个翻译的总得分
    public static function count_grade($param)
    {
        return self::getConnObj()->select(
            "SELECT ctcredit  FROM  pre_ct_translatedtext   WHERE tid=:tid ",
            [
                'tid' => $param['tid'],
            ]
        );

    }

	public static function get_info_by_tid($tid)
	{
		//tid: 译文对应论坛主题帖的tid
		return self::getConnObj()->select(
			"SELECT * from pre_ct_translatedtext ct_tran where tid=".$tid
		);
	}
	
}